<template>
	<view>
		<van-button type="info" @click="shareWechat">分享到微信 </van-button>
		<van-button type="primary" @click="shareCircle">分享到朋友圈 </van-button>
		<van-button type="default" @click="shareWeibo">分享到微博 </van-button>
		<van-button type="warning" @click="shareShoucang">分享到微信收藏 </van-button>
		<van-button type="danger" @click="shareQQ">分享到QQ </van-button>
		<van-button type="info" @click="shareXiaochengxu">分享到小程序 </van-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Provider:[]
			}
		},
		onShow () {
			this.getProvider()
		},
		methods: {
			//获取平台
			getProvider () {
				uni.getProvider({
					service:'share',
					success (res) {
						console.log(res.provider )
						this.Provider=res.provider 
					}
				})
			},
			//分享到微信
			shareWechat (){
				if(this.Provider.indexOf('weixin')){
					 uni.showToast({
					 	title:"分享到微信"
					 })
					 uni.share({
					     provider: "weixin",
					     scene: "WXSceneSession",
					     type: 0,
					     href: "http://uniapp.dcloud.io/",
					     title: "uni-app分享",
					     summary: "我正在使用HBuilderX开发uni-app，赶紧跟我一起来体验！",
					     imageUrl: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/uni@2x.png",
					     success: function (res) {
					         console.log("success:" + JSON.stringify(res));
					     },
					     fail: function (err) {
					         console.log("fail:" + JSON.stringify(err));
					     }
					 });
				}
			},
			//分享到朋友圈
			shareCircle () {
				if(this.Provider.indexOf('weixin')){
					uni.showToast({
						title:"分享到朋友圈"
					})
					uni.share({
					    provider: "weixin",
					    scene: "WXSenceTimeline",
					    type: 0,
					    href: "http://uniapp.dcloud.io/",
					    title: "uni-app分享",
					    summary: "我正在使用HBuilderX开发uni-app，赶紧跟我一起来体验！",
					    imageUrl: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/uni@2x.png",
					    success: function (res) {
					        console.log("success:" + JSON.stringify(res));
					    },
					    fail: function (err) {
					        console.log("fail:" + JSON.stringify(err));
					    }
					});
				}
			},
			//分享到收藏
			shareShoucang () {
				if(this.Provider.indexOf('weixin')){
					uni.showToast({
						title:'分享到收藏',
						icon:"none"
					})
					uni.share({
					    provider: "weixin",
					    scene: "WXSceneFavorite",
					    type: 0,
					    href: "http://uniapp.dcloud.io/",
					    title: "uni-app分享",
					    summary: "我正在使用HBuilderX开发uni-app，赶紧跟我一起来体验！",
					    imageUrl: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/uni@2x.png",
					    success: function (res) {
					        console.log("success:" + JSON.stringify(res));
					    },
					    fail: function (err) {
					        console.log("fail:" + JSON.stringify(err));
					    }
					});
				}
				
			},
			//分享到小程序
			shareXiaochengxu () {
				if(this.Provider.indexOf('weixin')){
					uni.showToast({
						title:'分享到小程序',
						icon:"none"
					})
					uni.share({
					    provider: 'weixin',
					    scene: "WXSceneSession",
					    type: 5,
					    imageUrl: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/app/share-logo@3.png',
					    title: '欢迎体验uniapp',
					    miniProgram: {
					        id: 'gh_abcdefg',
					        path: 'pages/index/index',
					        type: 0,
					        webUrl: 'http://uniapp.dcloud.io'
					    },
					    success: ret => {
					        console.log(JSON.stringify(ret));
					    }
					});
				}
			},
			//分享到	qq	
			shareQQ () {
				uni.showToast({
					title:'进到分享到qq',
					icon:'none'
				})
				if(this.Provider.indexOf('qq')){
					uni.showToast({
						title:'分享到qq',
						icon:'none'
					})
					uni.share({
					    provider: "qq",
						scene: "WXSceneSession",
					    type: 0,
					    href: "http://uniapp.dcloud.io/",
					    title: "uni-app分享",
					    summary: "我正在使用HBuilderX开发uni-app，赶紧跟我一起来体验！",
					    imageUrl: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/uni@2x.png",
					    success: function (res) {
					        console.log("success:" + JSON.stringify(res));
					    },
					    fail: function (err) {
					        console.log("fail:" + JSON.stringify(err));
					    }
					});
				} 
			},
			shareWeibo () {
				if(this.Provider.indexOf("sinaweibo")){
					uni.showToast({
						title:"分享到新浪微博",
						icon:'none'
					})
					
				}
			}
			
		}
	}
</script>

<style>

</style>
